<?php
class hrd_sub_departemen_model extends MY_Model {
	var $nama_tabel = 'hrd_sub_departemen';
	
	function GetJSON() {
		$ls_sql	= "	SELECT	A.*, B.nama_departemen, c.nama_pangkat
					FROM	".$this->nama_tabel." A
							LEFT JOIN hrd_departemen B ON A.id_departemen_fk = B.id_departemen_pk
							LEFT JOIN hrd_pangkat C ON a.id_pangkat_fk = c.id_pangkat_pk
					WHERE	(UPPER(id_sub_departemen_pk) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_sub_departemen) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(NVL(ket_sub_departemen,'')) LIKE '%".strtoupper(post('keyword'))."%')
							OR UPPER(nama_departemen) LIKE '%".strtoupper(post('keyword'))."%'
					ORDER BY ".(post('sort')=='' ? 'id_sub_departemen_pk' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
					
		return json_encode( $this->paging($ls_sql) );
					// print_r($ls_sql);
	}

	function Add($arr_data){
		$this->db->insert($this->nama_tabel, $arr_data);
	}

	function Update($arr_data, $arr_rule){
		$this->db->update($this->nama_tabel, $arr_data, $arr_rule);
	}

	function DeleteSingle($arr_rule) {
		try {
			$this->db->delete($this->nama_tabel, array('id_sub_departemen_pk' => $arr_rule['id_sub_departemen_pk']));
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

	function ComboDepartemen() {
		$ls_sql	= "	SELECT	ID_DEPARTEMEN_PK value,
							NAMA_DEPARTEMEN display
					FROM	HRD_DEPARTEMEN
					ORDER BY NAMA_DEPARTEMEN";
					
		$result	= $this->db->query($ls_sql);
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return array();
		}
	}

}
?>